package com.space.feign;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/5/17 2:46 下午
 */
public class FeignScannerConfigurer implements BeanDefinitionRegistryPostProcessor, InitializingBean {
    private String basePackage;

    public FeignScannerConfigurer() {
    }

    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        ClassPathFeignScanner scanner = new ClassPathFeignScanner(registry);
//        scanner.setResourcePattern("*.class");
//        scanner.setAnnotationClass(this.annotationClass);
//        scanner.setMarkerInterface(this.markerInterface);
//        scanner.setSqlSessionFactory(this.sqlSessionFactory);
//        scanner.setSqlSessionTemplate(this.sqlSessionTemplate);
//        scanner.setSqlSessionFactoryBeanName(this.sqlSessionFactoryBeanName);
//        scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName);
//        scanner.setResourceLoader(this.applicationContext);
//        scanner.setBeanNameGenerator(this.nameGenerator);
//        scanner.setMapperFactoryBeanClass(this.mapperFactoryBeanClass);
//        if (StringUtils.hasText(this.lazyInitialization)) {
//            scanner.setLazyInitialization(Boolean.valueOf(this.lazyInitialization));
//        }

        scanner.registerFilters();
        scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ",; \t\n"));
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(this.basePackage, "Property 'basePackage' is required");
    }
}
